﻿using System.IO;
using NUnit.Framework;

namespace CryptCompressTool.tests {

    [TestFixture]
    public class CryptFile {


        private const string TargetFileName = "TextFile1.txt.dnpcrypt";
        private const string SourceFileName = "TextFile1.txt";

        [SetUp]
        public void Setup() {
            File.Delete(TargetFileName);
            File.Delete(SourceFileName);
        }

        [Test]
        public void Crypt_And_Decrypt_TextFile() {
            var sut = new dnpCryptCompress.CryptCompress();
            sut.FileCrypt(@"..\..\" + SourceFileName, "123");
            File.Move(@"..\..\" + TargetFileName, TargetFileName);
            sut.FileDecrypt(TargetFileName, "123");

            var expected = File.ReadAllBytes(@"..\..\" + SourceFileName);
            var binReader = new BinaryReader(File.Open(SourceFileName, FileMode.Open));
            var result = new byte[expected.Length];
            binReader.Read(result, 0, expected.Length);

            Assert.That(result, Is.EqualTo(expected));
        }

    }
}
